const config = require("../mfo.config.js");
const { checkCustomLangPack } = require("../lib/utils");
const getDict = () => {
  const dictDefaultPath = "../config/" + config.language.langPack;
  let dictFilePath = checkCustomLangPack();
  if (dictFilePath) {
    return dictFilePath;
  } else {
    return require(dictDefaultPath);
  }
};
const dict = getDict();

const t = (type, name) => {
  return dict[type] ? dict[type][name] || name : name;
};

module.exports = (type, name) => {
  if (Array.isArray(name)) {
    for (let n = 0; n < name.length; n++) {
      const key = name[n].name;
      name[n].name = t(type, key);
    }
    return name;
  } else {
    return t(type, name);
  }
};
